package com.sec.android.app.myfiles.fragment;

import com.sec.android.app.myfiles.activity.FileListActivity;
import com.sec.android.app.myfiles.fragment.filelist.FileListFragment;
import com.sec.android.app.myfiles.fragment.home.HomeFragment;
import com.sec.android.app.myfiles.fragment.optimizestorage.OptimizeStorageFileListFragment;
import com.sec.android.app.myfiles.fragment.optimizestorage.OptimizeStorageOverviewFragment;
import com.sec.android.app.myfiles.fragment.securefilelist.SecureFileListFragment;
import com.sec.android.app.myfiles.fragment.trash.TrashFileListFragment;
import com.sec.android.app.myfiles.log.Log;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.module.abstraction.FileRecord.StorageType;
import com.sec.android.app.myfiles.module.cloud.CloudFileListFragment;
import com.sec.android.app.myfiles.module.local.recent.FullRecentListFragment;
import com.sec.android.app.myfiles.module.optimizestorage.OptimizeStorageFileRecord;
import com.sec.android.app.myfiles.module.preview.PreviewCompressListFragment;
import com.sec.android.app.myfiles.module.search.SearchFragment;
import com.sec.android.app.myfiles.module.shortcut.ManageShortcutListFragment;
import com.sec.android.app.myfiles.navigation.NavigationInfo;

public class FragmentBuilder {

    private static final String TAG = FragmentBuilder.class.getSimpleName() + "-HYL";

    public static AbsMyFilesFragment createFragment(FileListActivity activity, NavigationInfo navigationInfo) {
        int processId = activity.getProcessId();
        AbsMyFilesFragment ret = null;

        StorageType storageType = navigationInfo.getStorageType();
        Log.i(TAG, "createFragment. storageType = " + storageType);

        switch (storageType) {
            case Home:
                ret = new HomeFragment();
                break;
            case Search:
                ret = new SearchFragment();
                break;
            case Compress:
                ret = new PreviewCompressListFragment();
                break;
            case Recent:
                ret = new FullRecentListFragment();
                break;
            case Shortcut:
                ret = new ManageShortcutListFragment();
                break;
            case OptimizeStorage:
                ret = getOptimizeStorageFragment(navigationInfo.getCurRecord());
                break;
            case Cloud:
                ret = new CloudFileListFragment();
                break;
            case Trash:
                ret = new TrashFileListFragment();
                break;
            case SecureLocal:
                ret = new SecureFileListFragment();
                break;

        }

        if (ret == null) {
            ret = new FileListFragment();
        }

        ret.setNavigationInfo(navigationInfo);
        ret.setProcessId(processId);

        return ret;
    }

    private static AbsMyFilesFragment getOptimizeStorageFragment(FileRecord curRecord) {
        AbsMyFilesFragment ret = null;
        if (curRecord != null) {
            if (OptimizeStorageFileRecord.getOptimizeStorageType(curRecord.getFullPath()) ==
                    FileRecord.OptimizeStorageType.Overview) {
                ret = new OptimizeStorageOverviewFragment();
            } else {
                ret = new OptimizeStorageFileListFragment();
            }
        }
        return ret;
    }
}
